@extends('layouts.default') @section('main')
    <link rel="stylesheet" href="/css/uniform.css" />
    <link rel="stylesheet" href="/css/select2.css" />

    <div id="content">
        <div id="content-header">
            <div id="breadcrumb"> <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a>
                <a href="#" class="tip-bottom">项目管理</a>
                <a href="#" class="current">推荐方管理</a>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    @if(in_array('add',$actions))<a href="{{url('project/create-rec?id='.$id)}}"><button class="btn">新增</button></a>@endif

                    <div class="widget-box">
                        <div class="widget-title">
                            <span class="icon">
                                <input type="checkbox" id="title-checkbox" name="title-checkbox" />
                            </span>
                            <h5>推荐方管理</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <table class="table table-bordered table-striped with-check" id="table">
                                <thead>
                                <tr>
                                    <th><i class="icon-resize-vertical"></i></th>
                                    <th>头像</th>
                                    <th>名称</th>
                                    <th>职位</th>
                                    <th>描述</th>
                                    <th>uid</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($lists as $key => $list)
                                    <tr>
                                        <td><input type="checkbox" value="{{$list->id}}" /></td>
                                        <td><img width="100px" height="100px" src="{{getImage($list->avatar)}}" /></td>
                                        <td >{{$list->name}}</td>
                                        <td >{{$list->position}}</td>
                                        <td title="{{ $list->description }}">{{ cut_str($list->description,14) }}</td>
                                        <td >@if($list->uid) {{$list->uid}} @endif</td>
                                        <td>@if($list->status == 1)<i class="icon-ok"></i>@elseif($list->status == 0)<i class="icon-remove-sign"></i>@endif</td>
                                        <td class="center">
                                            @if(in_array('edit',$actions))<a data-original-title="编辑" id="edit" class="tip" href="{{url('project/edit-rec?id='.$list->id)}}"><i class="icon-pencil"></i></a>@endif
                                            @if(in_array('delete',$actions))<a data-original-title="删除" data-toggle="modal" id="delete" class="tip project_delete" href="#myAlert" p_id="{{$list->id}}"><i class="icon-remove"></i></a> @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <?php echo $lists->render();?>
                </div>
            </div>
        </div>
    </div>
    <div>
        <div id="myAlert" class="modal hide">
            <div class="modal-header">
                <button data-dismiss="modal" class="close" type="button">×</button>
                <h3>提示</h3>
            </div>
            <div class="modal-body">
                <p>确认删除这条数据吗？</p>
            </div>
            <div class="modal-footer">
                <a data-dismiss="modal" class="btn btn-primary" href="javascript:void(0);">确定</a>
                <a data-dismiss="modal" class="btn" href="javascript:void(0);">取消</a>
            </div>
        </div>
        <form action="{{url('project/del-rec')}}" method="post" id="adForm">
            <input type="hidden" name="pid" value="0">
        </form>
    </div>
    <script src="/js/matrix.tables.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>

    <script>

        $(".project_delete").click(function(){
            var p_id = $(this).attr("p_id");
            $("input[name='pid']").val(p_id);
        });
        $(".btn-primary").click(function(){
            var p_id = $("input[name='pid']").val();
            if(p_id == 0){
                alert('参数异常');
                return;
            }

            ajaxRequest($('#adForm').serializeArray(),$('#adForm').attr('action'),function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    alert(data.message);
                }
            });
        });


        function allchk(){
            var chknum = $("#table :checkbox").size();//选项总个数
            var chk = 0;
            $("#table :checkbox").each(function () {
                if($(this).prop("checked")==true){
                    chk++;
                }
            });
            if(chknum==chk){
                $("#title-checkbox").prop("checked",true);
            }else{
                $("#title-checkbox").prop("checked",false);
            }
        }

        $("#title-checkbox").click(function(){
            if(this.checked){
                $("#table :checkbox").prop("checked", true);
            }else{
                $("#table :checkbox").prop("checked", false);
            }
        });

        $("#table :checkbox").click(function(){
            allchk();
        });

        $("#mass").click(function(){
            var valArr = new Array();

            $("#table :checkbox").each(function(i){
                if($(this).prop('checked')==true){
                    valArr[i] = $(this).val();
                }
            });
            var vals = valArr.join(',');
            var status = ($('#status').val());
            ajaxRequest({ project: vals, status: status },"{{url('project/mass-audit')}}",function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    alert(data.message);
                }
            });
        });

    </script>
@stop
